<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
     创建实例 - 初始化渲染 
      1. 准备容器
      2. 引包-官网 开发版本 - 错误提示更完善
      3. 创建vue实例
      4. 指定配置项
         el 指定挂载点
         data 提供数据
   -->
    <div id="app" class="fruit-shop">
        <h1>欢迎光临 Vue开发的收银系统_水果店</h1>
        <p>苹果 {{ price }}元/斤, 折扣 <8折>
        </p>
        <span>
            <p>请输入你要购买的斤数
            <input type="number" v-model.number="quantity" placeholder="请输入你要购买的斤数">
            </p>
        </span>
        <button @click="calculate">结账买单~</button>
        <div class="receipt">
            结账单: 总价: {{ totalPrice }}元 折后价: {{ discountedPrice }}元 省了{{ savedAmount }}元
        </div>
    </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
              price: 10,
              totalPrice: 0,
              discountRate: 0.8,
              quantity: 0,
              discountedPrice: 0,
              savedAmount: 0
            },
            methods :{
                calculate () {
                    //计算总价
                    this.totalPrice = this.price * this.quantity;
                    //计算折后价
                    this.discountedPrice = this.totalPrice * this.discountRate;
                    //省了多少
                    this.savedAmount=this.totalPrice - this.discountedPrice
                }
            }
        })
    </script>
</body>
<style>
    .fruit-shop {
        max-width: 600px;
        margin: auto;
        text-align: center;
    }

    .receipt {
        margin-top: 20px;
    }
</style>
</html>